<!--
  $Id: markers.html,v 1.5 2011-05-11 12:59:02 gaudenz Exp $
  Copyright (c) 2006-2010, JGraph Ltd
  
  Markers example for mxGraph. This example demonstrates creating
  custom markers and customizing the built-in markers.
-->
<html>
<head>
	<title>Markers example for mxGraph</title>

	<!-- Sets the basepath for the library if not in same directory -->
	<script type="text/javascript">
		mxBasePath = '../src';
	</script>

	<!-- Loads and initializes the library -->
	<script type="text/javascript" src="http://mxclient.jgraph.com/demo/mxgraph/src/js/mxclient.php?version=1.7.0.0"></script>

	<!-- Example code -->
	<script type="text/javascript">
		// Program starts here. Creates a sample graph in the
		// DOM node with the specified ID. This function is invoked
		// from the onLoad event handler of the document (see below).
		function main(container)
		{
			// Checks if the browser is supported
			if (!mxClient.isBrowserSupported())
			{
				// Displays an error message if the browser is not supported.
				mxUtils.error('Browser is not supported!', 200, false);
			}
			else
			{
				// Enables crisp rendering in SVG
				mxShape.prototype.crisp = true;
				mxConnector.prototype.allowCrispMarkers = true;
				
				// Creates the graph
				var graph = new mxGraph(container);
				
				// Sets default styles
				graph.getStylesheet().getDefaultVertexStyle()['fillColor'] = '#FFFFFF';
				graph.getStylesheet().getDefaultVertexStyle()['strokeColor'] = '#000000';
				graph.getStylesheet().getDefaultVertexStyle()['fontColor'] = '#000000';
				graph.getStylesheet().getDefaultVertexStyle()['fontStyle'] = '1';
				graph.getStylesheet().getDefaultEdgeStyle()['strokeColor'] = '#000000';
				graph.getStylesheet().getDefaultEdgeStyle()['fontColor'] = '#000000';
				graph.getStylesheet().getDefaultEdgeStyle()['fontStyle'] = '0';
				graph.getStylesheet().getDefaultEdgeStyle()['fontStyle'] = '0';
				graph.getStylesheet().getDefaultEdgeStyle()['startSize'] = '8';
				graph.getStylesheet().getDefaultEdgeStyle()['endSize'] = '8';
				
				// Enables guides
				mxGraphHandler.prototype.guidesEnabled = true;
				mxEdgeHandler.prototype.snapToTerminals = true;
				
				// Defines custom marker
				mxMarker.markers['dash'] = function(node, type, pe, nx, ny, strokewidth, size, scale, isVml)
				{
					if (isVml)
					{
						node.setAttribute('path', 'm' + Math.floor(pe.x - nx / 2- ny / 2) + ' ' + Math.floor(pe.y - ny / 2 + nx / 2) +
							' l ' + Math.floor(pe.x + ny / 2 - 3 * nx / 2) + ' ' + Math.floor(pe.y - 3 * ny / 2 - nx / 2) +
							' e');
					}
					else
					{
						node.setAttribute('d', 'M ' + (pe.x - nx / 2 - ny / 2) + ' ' + (pe.y - ny / 2 + nx / 2) +
								' L ' + (pe.x + ny / 2 - 3 * nx / 2) + ' ' + (pe.y - 3 * ny / 2 - nx / 2) +
								' z');
					}
					
					// Returns the offset for the edge
					return new mxPoint(0, 0);
				};
	
				// Adds a new style that handles filling of markers
				mxConnectorRedrawMarker = mxConnector.prototype.redrawMarker;
				mxConnector.prototype.redrawMarker = function(node, type, p0, pe, color, size)
				{
					var result = mxConnectorRedrawMarker.apply(this, arguments);
					var key = (this.start == node) ? 'fillStart' : 'fillEnd';
					
					if (this.style[key] == 0)
					{
						if (mxUtils.isVml(node))
						{
							node.setAttribute('filled', 'false');
						}
						else
						{
							node.setAttribute('fill', 'none');
						}
					}
					
					return result;
				};

				// Populates the graph
				var parent = graph.getDefaultParent();
								
				graph.getModel().beginUpdate();
				try
				{
					var v1 = graph.insertVertex(parent, null, 'v1', 20, 20, 80, 30);
					var v2 = graph.insertVertex(parent, null, 'v2', 440, 20, 80, 30);
					var e1 = graph.insertEdge(parent, null, '', v1, v2, 'dashed=1;'+
						'startArrow=oval;endArrow=block;sourcePerimeterSpacing=4;fillStart=0;fillEnd=0;');
					var e11 = graph.insertVertex(e1, null, 'Label', 0, 0, 60, 12,
						'shape=label;image=editors/images/connect.gif;' +
						'spacing=0;spacingRight=22;align=right;imageAlign=right;imageHeight=16;imageWidth=16;' +
						'fillColor=white;strokeColor=none;fontColor=#000000;fontStyle=0;');
					e11.geometry.offset = new mxPoint(-30, -6);
					e11.geometry.relative = true;
					e11.connectable = false;
					
					var v3 = graph.insertVertex(parent, null, 'v3', 20, 120, 80, 30);
					var v4 = graph.insertVertex(parent, null, 'v4', 440, 120, 80, 30);
					var e2 = graph.insertEdge(parent, null, 'Label', v3, v4,
						'startArrow=dash;startSize=12;endArrow=block;labelBackgroundColor=#FFFFFF;');
				}
				finally
				{
					graph.getModel().endUpdate();
				}
			}
		};
	</script>
</head>
<body onload="main(document.getElementById('graphContainer'))">
	<div id="graphContainer"
		style="overflow:hidden;width:641px;height:381px;border:1px solid gray;cursor:default;">
	</div>
</body>
</html>